package com.yami.shop.multishop.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.MuseumModel;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.MuseumModelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 博物馆模型管理
 *
 * @author lsr
 */
@RestController
@RequestMapping("/shop/museumModel")
@Tag(name="博物馆模型相关接口")
public class MuseumModelController {

    @Autowired
    private MuseumModelService museumModelService;

    @GetMapping("/page")
    @Operation(summary =  "分页获取博物馆模型信息列表", description = "分页获取博物馆模型信息列表")
    public ServerResponseEntity<IPage<MuseumModel>> page(PageParam<MuseumModel> pageDTO, @ParameterObject MuseumModel brandDTO) {
        QueryWrapper<MuseumModel> museumQueryWrapper = new QueryWrapper<>();
        museumQueryWrapper.like(ObjectUtil.isNotEmpty(brandDTO.getName()),"name",brandDTO.getName());
        museumQueryWrapper.eq("shop_id", SecurityUtils.getShopUser().getShopId());
        IPage<MuseumModel> brandPage = museumModelService.page(pageDTO,museumQueryWrapper);
        return ServerResponseEntity.success(brandPage);
    }

    @GetMapping("/info/{brandId}")
    @Operation(summary =  "获取博物馆模型信息", description = "根据Id获取博物馆模型信息")
    @Parameter(name = "id", description = "博物馆模型id")
    public ServerResponseEntity<MuseumModel> getByBrandId(@PathVariable Long brandId) {
        MuseumModel museum = museumModelService.getById(brandId);
        return ServerResponseEntity.success(museum);
    }

    @PostMapping
    @Operation(summary =  "保存博物馆模型信息", description = "保存博物馆模型信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody MuseumModel museum) {
        museum.setShopId(SecurityUtils.getShopUser().getShopId());
        museumModelService.save(museum);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary =  "更新博物馆模型信息", description = "更新博物馆模型信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody MuseumModel museum) {
        museumModelService.updateById(museum);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary =  "删除博物馆模型信息", description = "根据博物馆模型id删除博物馆模型信息")
    @Parameter(name = "id", description = "博物馆模型id")
    public ServerResponseEntity<Void> delete(@RequestParam Long brandId) {
        museumModelService.removeById(brandId);
        return ServerResponseEntity.success();
    }

}
